<template>
    <div>
         <div class="headstyle">
            <el-row :gutter="20">
                <el-col :span="16">
                    <div class="grid-content bg-purple">
                    <span class="locsty"><i class="el-icon-location iconsty"></i>当前位置：密码修改</span>
                    </div>
                </el-col>        
                <el-col :span="8" class="loc-index">
                    <div class="grid-content bg-purple">
                        <!-- <el-button type="" @click="goTo('/adminmanage')" class="backbtn">返回</el-button>                    -->
                    </div>
                </el-col>
            </el-row>
        </div>
        <div class="contentstyle">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="160px" class="demo-ruleForm">
              <el-form-item label="当前账号" prop="te_number">
                  <el-input v-model="ruleForm.te_number" class="inputEdit" readonly ></el-input>
              </el-form-item>
              <el-form-item label="原密码" prop="oldpsw">
                  <el-input type="password" v-model="ruleForm.oldpsw" class="inputEdit" auto-complete="new-password"></el-input>
              </el-form-item>
              <el-form-item label="新密码" prop="newpsw">
                  <el-input type="password" v-model="ruleForm.newpsw" class="inputEdit"></el-input>
              </el-form-item>                             
              <el-form-item label="确认新密码" prop="surepsw">
                  <el-input v-model="ruleForm.surepsw" class="inputEdit" type="password"></el-input>                 
              </el-form-item>                       
              <el-form-item>                
                  <el-button type="primary btnsty" @click="submitForm('ruleForm')">确定</el-button>               
              </el-form-item>    
            </el-form>
        </div>
    </div>
</template>
<script>
export default {
  data() {
    var validatesurepsw = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入新密码"));
      } else {
        if (this.ruleForm.newpsw != this.ruleForm.surepsw) {
          callback(new Error("两次输入的新不一致，请确认"));
        } else {
          callback();
        }
      }
    };
    return {
      ruleForm: {
        te_number: "", //导师工号
        oldpsw: "", //导师姓名
        newpsw: "", //所属部门
        surepsw: "" //一级业务维度
      },
      rules: {
        oldpsw: [{ required: true, message: "请输入原密码", trigger: "blur" }],
        newpsw: [
          { required: true, message: "请输入新密码", trigger: "blur" },
          { min: 8, max: 16, message: "长度在 8 到 16 个字符", trigger: "blur" }
        ],
        surepsw: [
          { required: true, validator: validatesurepsw, trigger: "blur" }
        ]
      }
    };
  },
  mounted() {
    if (this.$store.state.teacherinfo == null) {
      this.$message({
        type: "info",
        message: "登录失效，请重新登录"
      });
      this.$router.push("/login");
    } else {
      this.ruleForm.te_number = JSON.parse(
        this.$store.state.teacherinfo
      ).Te_number;
    }
  },
  methods: {
    submitForm(formName) {
      if (this.$store.state.teacherinfo == null) {
        this.$message({
          type: "info",
          message: "登录失效，请重新登录!"
        });
        this.$router.push("/login");
      } else {
        var list = {
          Te_number: this.ruleForm.te_number,
          Te_psw: this.ruleForm.oldpsw
        };
        this.$axios
          .put("/Login/" + this.ruleForm.newpsw, list)
          .then(Json => {
            if (Json.data === 1) {
              this.$message("原密码输入错误！");
              return false;
            }
            if (Json.data === 2) {
              this.$message("此用户不存在！");
              return false;
            }

            this.$message("密码修改成功！");
          })
          .catch(error => {});
      }
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.ywshowflag = false;
    }
  }
};
</script>

<style scoped>
/*.loc-index {
  padding-left: 150px !important;
}*/
.backbtn {
  width: 100px;
}
.headstyle {
  border-bottom: 2px solid #e5e5e5;
  padding-bottom: 20px;
}
.locsty {
  font-size: 16px;
  font-family: "Microsoft YaHei";
}
.iconsty {
  color: #53b9fe;
  font-size: 22px;
}
a {
  text-decoration: none;
  color: black;
}
.contentstyle {
  width: 75%;
  padding: 40px;
  padding-left: 100px;
}
.inputEdit {
  width: 48%;
}
.selectsty {
  width: 48%;
}
.btnsty {
  width: 85px;
}
</style>

